<?php
/**
 * @filesource /modules/user/Form/Register.php
 * @abstract Generate a register form, where no lable is set
 *     see /modules/user/views/register/register.phtml for how the form is generated.
 */
class user_Form_Register extends Zend_Form
{

    protected $_noDecorator = array(
        'ViewHelper', 
        'Errors'
    );

    public function cluBuild()
    {
    
        $user = new user_Model_User(); //for DbUnique validators
        // set the method for the display form to POST
        $this->setMethod('post');
		$this->setAction($this->getView()->hvnUrl(array('action' => 'register'),'account')); 
        
		//common filters & validators for all fields
        $filterTrim = new Zend_Filter_StringTrim();
        $validatorNotEmpty = new Zend_Validate_NotEmpty();
        $validatorNotEmpty->setMessage(t(418));


        // username
        $username = new Zend_Form_Element_Text('name', array('disableLoadDefaultDecorators' => true,
                                                                 'class' => 'inputText',
                                                                 'required' => true));
        $validatorAlnum = new Zend_Validate_Alnum();
        $validatorAlnum->setMessage(t(419));
        $validatorStringLength = new Zend_Validate_StringLength(3, 32);
        $validatorStringLength->setMessages(array(
            Zend_Validate_StringLength::TOO_SHORT => t(420),
            Zend_Validate_StringLength::TOO_LONG => t(420),
            )
        );
        $validatorUniqueUsername = new Clu_Validate_DbUnique($user, 'name');
        $validatorUniqueUsername->setMessage(t(421));
             
        $username->addValidator($validatorNotEmpty, true)
                 ->addFilter($filterTrim)
                 ->addValidator($validatorAlnum)
                 ->addValidator($validatorStringLength)
                 ->addValidator($validatorUniqueUsername)
                 ->addDecorators($this->_noDecorator);
                 
        $this->addElement($username);
        

        // add an email element
        $mail = new Zend_Form_Element_Text('mail', array('disableLoadDefaultDecorators' => true,
                                                                 'class' => 'inputText',
                                                                 'required' => true));
        $validatorEmail = new Zend_Validate_EmailAddress();
        $validatorEmail->setMessages(
            array(
                Zend_Validate_EmailAddress::INVALID            => t(743),
                Zend_Validate_EmailAddress::INVALID_HOSTNAME   => t(744),
        ));

        $validatorUniqueEmail = new Clu_Validate_DbUnique($user, 'mail');
        $validatorUniqueEmail->setMessage(t(422));
        
        $mail->addValidator($validatorNotEmpty, true)
              ->addFilter($filterTrim)
              ->addValidator($validatorEmail)
              ->addValidator($validatorUniqueEmail) 
              ->addDecorators($this->_noDecorator);
              
        $this->addElement($mail);

        // pass
        $pass = new Zend_Form_Element_Password('pass',  array('disableLoadDefaultDecorators' => true,
                                                                 'required' => true));
        $pass->addValidator($validatorNotEmpty, true)
                 ->addValidator(new Zend_Validate_StringLength(3))
                 ->addDecorators($this->_noDecorator);
                 
        $this->addElement($pass);
 
        // pass again
        $pass2 = new Zend_Form_Element_Password('pass2',  array('disableLoadDefaultDecorators' => true,
                                                                 'required' => true));
        $validatorPassword = new Clu_Validate_PasswordMatch('pass');
        $validatorPassword->setMessage(t(415));
        $pass2->addValidator($validatorPassword)
                  ->addDecorators($this->_noDecorator);
        
        $this->addElement($pass2);
		
		//accountType
		$accountType = new Zend_Form_Element_Select('type', array('disableLoadDefaultDecorators' => true,
                                                                 'required' => true));
		$accountType//->addMultiOption('none', t(481))
					->addMultiOption(1, t(479))
					->addMultiOption(2, t(480));
		$accountType->addDecorators($this->_noDecorator);
		$accountType->setValue(2);					
		$this->addElement($accountType);
		                                                                
	   // add element captcha
	   $elementCaptcha =
	    new Zend_Form_Element_Captcha(
					   'captcha_user_register',
					   array(
						   'captcha' => 'Image',
						   'captchaOptions' => 	array(
										    'captcha' => 'Image',
										    'wordLen' => 4,
										    'timeout' => 300,
										    'imgDir'  => APP_PATH.'/public/captcha',
										    'imgUrl' => '/public/captcha/',
										    'width' => 175,
										    'height' => 60,
										    'font' => APP_PATH.'/public/captcha/font/tahoma.ttf',
										    'DotNoiseLevel' => 10,  
		        							'LineNoiseLevel' => 1,
											'expiration' => 3, //TODO:
		        							'gcFreq' => 1
										   )
						  )
		);
	   
	   $elementCaptcha//->setLabel(t(39).':')
	   				  ->setAttrib('id','captcha_registrationImage')
                      ->setRequired(true);
       $this->addElement($elementCaptcha);
               
        //submit
        // add the submit button
        $submit = new Zend_Form_Element_Submit('submit', array('disableLoadDefaultDecorators' => true, 
                                                               'label' => t(423) ));
        $submit->addDecorators($this->_noDecorator);
        $this->addElement($submit);

    }
}

?>